public class Solution {
    public int deleteAndEarn(int[] nums) {
// 两个元素的大小不能相邻
        int[] arr = new int[10001];

        for (int x : nums) {
            //统计x在x位置出现的总和
            arr[x] += x;
        }
        int n = 10001;
        int[] f = new int[n];
        int[] g = new int[n];

        f[0] = arr[0];
        g[0] = 0;

        for (int i = 1; i < n; i++) {
            f[i] = arr[i] + g[i - 1];
            g[i] = Math.max(f[i - 1], g[i - 1]);
        }

        return Math.max(f[n - 1], g[n - 1]);

    }
}